﻿using System;
using System.Web.UI;
using FFIV.Lib.Model;
using FFIV.Lib.Utilities;

namespace FFIV.Lib.WebExtension
{
	public abstract class FFWebPageBase : Page
	{
		protected override void OnPreInit(EventArgs e)
		{
			base.OnPreInit(e);

			CheckPremission();
		}

		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);

			try
			{
				InitialFileds();
				BindingEvents();
				ShowMessage();
			}
			catch (PermissionException)
			{
				Response.Redirect(UrlUtility.GetPermissionErrorUrl());
			}
		}

		protected abstract void InitialFileds();

		protected abstract void BindingEvents();

		public abstract void ShowMessage();

		public abstract Permissions RequiredPermission
		{
			get;
		}

		public void CheckPremission()
		{
			if (RequiredPermission < UsersUtility.GetCurrentUserRole())
			{
				Response.Redirect(UrlUtility.GetPermissionErrorUrl());
			}
		}
	}
}